Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-zoom

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-zoom

Pan and zoom SVG, HTML or Canvas using mouse or touch input.

  • 1.8.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3M
decreased by-44.72%
Maintainers
1
Weekly downloads
 
Created

What is d3-zoom?

The d3-zoom package is a JavaScript library that allows for interactive zooming and panning of elements in a document, typically used with SVG graphics. It is part of the D3 (Data-Driven Documents) collection of tools for manipulating documents based on data. d3-zoom enables users to apply zoom and pan transformations to visualizations, enhancing the interactivity and accessibility of data representations.

What are d3-zoom's main functionalities?

Zoom and Pan

This feature allows users to add zoom and pan interactions to an SVG element. The 'zoom' event listener applies the transformation to the SVG, updating its position and scale according to user interactions like mousewheel scrolling and dragging.

{"svg.call(d3.zoom().on('zoom', (event) => { svg.attr('transform', event.transform); }))"}

Control Zoom Scale

This feature lets users define the scale extent for the zoom, limiting how much the user can zoom in or out. In this example, the zoom scale is limited between 1x and 8x.

{"svg.call(d3.zoom().scaleExtent([1, 8]).on('zoom', (event) => { svg.attr('transform', event.transform); }))"}

Translate Extent

This feature restricts the panning to a specified rectangular area. In the code sample, the translate extent is set to the dimensions of the SVG, preventing panning outside of the SVG's viewbox.

{"svg.call(d3.zoom().translateExtent([[0, 0], [width, height]]).on('zoom', (event) => { svg.attr('transform', event.transform); }))"}

Programmatic Zooming

This feature allows for programmatic control of the zoom level, enabling transitions to a specific zoom level or transform. In this example, the SVG is programmatically zoomed to 2x scale over a 750ms transition.

{"svg.transition().duration(750).call(zoom.transform, d3.zoomIdentity.scale(2))"}

Other packages similar to d3-zoom

Keywords

FAQs

Package last updated on 10 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc